﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;

namespace VideoFlowTagger
{
    public static class Extensions
    {
        public static String GetStringValue(this Enum value)
        {
            Type type = value.GetType();
            FieldInfo fieldInfo = type.GetField(value.ToString());
            AtomicParsleyTagAttribute[] attributes = fieldInfo.GetCustomAttributes(
                typeof(AtomicParsleyTagAttribute), false) as AtomicParsleyTagAttribute[];

            return attributes.Length > 0 ? attributes[0].Value : null;
        }

        public static String GetStringValue(this Object value)
        {
            Type type = value.GetType();
            FieldInfo fieldInfo = type.GetField(value.ToString());
            AtomicParsleyTagAttribute[] attributes = fieldInfo.GetCustomAttributes(
                typeof(AtomicParsleyTagAttribute), false) as AtomicParsleyTagAttribute[];

            return attributes.Length > 0 ? attributes[0].Value : null;
        }

        public static String GetAtomName(this Object value)
        {
            Type type = value.GetType();
            FieldInfo fieldInfo = type.GetField(value.ToString());
            AtomTagAttribute[] attributes = fieldInfo.GetCustomAttributes(
                typeof(AtomTagAttribute), false) as AtomTagAttribute[];

            return attributes.Length > 0 ? attributes[0].Value : null;
        }
    }
}
